#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e3+100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
struct Edge{
   LL to,val;
};
vector<Edge>g[maxn];
LL dp[maxn];
void dfs(LL u,LL fa,LL li){
     dp[u]=0;
     bool flag=1;
     for(LL i=0;i<g[u].size();i++){
         LL v=g[u][i].to;LL cost=g[u][i].val;
         if(v==fa) continue;
         dfs(v,u,li);
         flag=0;
         if(cost>li){
            dp[u]+=dp[v];
         }
         else{
            dp[u]+=min(dp[v],cost);
         }
     }
     if(flag) dp[u]=1e13;
}
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   LL n,m;
   while(cin>>n>>m&&n&&m){
      for(LL i=0;i<maxn;i++){
         g[i].clear();
      }
      for(LL i=1;i<n;i++){
          LL u,v,val;cin>>u>>v>>val;
          g[u].push_back({v,val});
          g[v].push_back({u,val});
      }
      LL l=1;LL r=1e13;
      while(l<r){
           LL mid=(l+r)>>1;
           dfs(1,0,mid);
           if(dp[1]<=m) r=mid;
           else l=mid+1;
      }
      if(l==1e13){
        cout<<"-1"<<"\n";
      }
      else{
        cout<<l<<"\n";
      }
   }
   return 0;
}
